package com.culture.bootdemo.common.basevo;

/**
 * @author ：wen
 * @date ：Created in 2019/8/2 18:26
 * @description：:
 */
public class PageUtil {
    private Integer limit = 10; // 当前页大小//每页行数
    private Integer total = 0; // 总记录数
    private Integer currentPage = 1; // 当前页
    private Integer totalPage = 0; // 总页数


    public PageUtil() {
        super();
    }

    public PageUtil(Integer limit, Integer currentPage, Integer total) {
        super();
        this.limit = limit;
        this.currentPage = currentPage;
        if (total > 0) {
            this.total = total;

            if (total % this.limit > 0) {
                this.totalPage = (total / this.limit) + 1;
            } else {
                this.totalPage = (total / this.limit);
            }
        } else {
            this.total = 0;
        }
    }

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        if (total > 0) {
            this.total = total;

            if (total % this.limit > 0) {
                this.totalPage = (total / this.limit) + 1;
            } else {
                this.totalPage = (total / this.limit);
            }
        } else {
            this.total = 0;
        }
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }


    /**
     *
     * @param currentPage 当前页数
     * @param limit 每页限制条数
     * @return  返回值：mysql中  limit语句中的第一个参数
     */
    public static int getOffset(int currentPage, int limit) {
        if (currentPage == 0) {
            currentPage = 1;
        }
        if (limit == 0) {
            limit = 10;
        }
        return (currentPage - 1) * limit;
    }
}
